package com.media.system.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 用户实体
 * 
 * @author Claude
 * @since 2024-01-20
 */
@Data
@TableName("users")
@Schema(description = "用户实体")
public class User {

    /**
     * 用户ID
     */
    @TableId(type = IdType.AUTO)
    @Schema(description = "用户ID")
    private Long userId;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    @Size(min = 2, max = 30, message = "用户名长度必须在2-30个字符之间")
    @Schema(description = "用户名")
    private String username;

    /**
     * 昵称
     */
    @NotBlank(message = "昵称不能为空")
    @Size(min = 2, max = 30, message = "昵称长度必须在2-30个字符之间")
    @Schema(description = "昵称")
    private String nickname;

    /**
     * 邮箱
     */
    @Email(message = "邮箱格式不正确")
    @Size(max = 50, message = "邮箱长度不能超过50个字符")
    @Schema(description = "邮箱")
    private String email;

    /**
     * 手机号码
     */
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    @Schema(description = "手机号码")
    private String phone;

    /**
     * 密码哈希
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @TableField("password_hash")
    @Schema(description = "密码哈希", accessMode = Schema.AccessMode.WRITE_ONLY)
    private String passwordHash;

    /**
     * 密码（用于接收前端输入）
     */
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @NotBlank(message = "密码不能为空")
    @Size(min = 6, max = 20, message = "密码长度必须在6-20个字符之间")
    @Schema(description = "密码", accessMode = Schema.AccessMode.WRITE_ONLY)
    private String password;

    /**
     * 头像地址
     */
    @TableField("avatar_url")
    @Schema(description = "头像地址")
    private String avatar;

    /**
     * 用户性别（0男 1女 2未知）
     */
    @TableField("gender")
    @Schema(description = "性别", allowableValues = {"0", "1", "2"})
    private Integer sex;

    /**
     * 生日
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @TableField("birth_date")
    @Schema(description = "生日")
    private LocalDate birthday;

    /**
     * 个人简介
     */
    @Size(max = 500, message = "个人简介不能超过500个字符")
    @Schema(description = "个人简介")
    private String bio;

    /**
     * 用户状态（0正常 1停用）
     */
    @Schema(description = "状态", allowableValues = {"0", "1"})
    private Integer status;

    /**
     * 最后登录IP
     */
    @TableField("last_login_ip")
    @Schema(description = "最后登录IP")
    private String loginIp;

    /**
     * 最后登录时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("last_login_at")
    @Schema(description = "最后登录时间")
    private LocalDateTime loginDate;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("created_at")
    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("updated_at")
    @Schema(description = "更新时间")
    private LocalDateTime updateTime;
}